package com.titleevaluation.controller;

import com.titleevaluation.entity.SocialPositions;
import com.titleevaluation.service.SocialPositionsService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/applications/{applicationId}/social-positions")
public class SocialPositionsController {

    private final SocialPositionsService socialPositionsService;

    public SocialPositionsController(SocialPositionsService socialPositionsService) {
        this.socialPositionsService = socialPositionsService;
    }

    @PostMapping
    public ResponseEntity<SocialPositions> createSocialPositions(@PathVariable Long applicationId, @RequestBody SocialPositions socialPositions) {
        SocialPositions createdSocialPositions = socialPositionsService.createSocialPositions(applicationId, socialPositions);
        return ResponseEntity.ok(createdSocialPositions);
    }

    @GetMapping
    public ResponseEntity<List<SocialPositions>> getSocialPositionsByApplicationId(@PathVariable Long applicationId) {
        List<SocialPositions> socialPositions = socialPositionsService.getSocialPositionsByApplicationId(applicationId);
        return ResponseEntity.ok(socialPositions);
    }

    @GetMapping("/{id}")
    public ResponseEntity<SocialPositions> getSocialPositionsById(@PathVariable Long id) {
        return socialPositionsService.getSocialPositionsById(id)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }

    @PutMapping("/{id}")
    public ResponseEntity<SocialPositions> updateSocialPositions(@PathVariable Long id, @RequestBody SocialPositions socialPositions) {
        SocialPositions updatedSocialPositions = socialPositionsService.updateSocialPositions(id, socialPositions);
        return ResponseEntity.ok(updatedSocialPositions);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteSocialPositions(@PathVariable Long id) {
        socialPositionsService.deleteSocialPositions(id);
        return ResponseEntity.noContent().build();
    }
}

